home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Open/Close/Reorg UID file *)
- (* *)
- (* Copyright 1988, 1989 by H. Roy Engehausen. All rights reserved. *)
- (* This software may be freely distributed and used, but it may not *)
- (* under any circumstances be sold by anyone other than the author. *)
- (* It may be distributed by a commercial company as long as it is *)
- (* for no cost. *)
- (* *)
- (*===========================================================================*)
-
- (*===========================================================================*)
- (* Open uid file *)
- (*===========================================================================*)
-
- PROCEDURE open_uid(fileid : file_name_str);
-
- VAR
- i : WORD;
- uid_buffer : user_record_type;
- uid_index_current : user_index_ptr;
-
- BEGIN;
-
- (*-----------------------------------------------------------------------*)
- (* Open uid file for read *)
- (*-----------------------------------------------------------------------*)
-
- ASSIGN(uid_file, fileid);
- {$I-}
- RESET(uid_file);
- {$I+}
-
- (*-----------------------------------------------------------------------*)
- (* File doesn't exist. Initialize it *)
- (*-----------------------------------------------------------------------*)
-
- IF IORESULT <> 0 THEN
- BEGIN;
-
- REWRITE(uid_file);
-
- FILLCHAR(uid_buffer, SIZEOF(uid_buffer), CHR(0));
- uid_buffer.user_i_ptr := PTR(sys_version, sys_version);
- WRITE(uid_file, uid_buffer);
-
- CLOSE(uid_file);
-
- RESET(uid_file);
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Check the version of the file *)
- (*-----------------------------------------------------------------------*)
-
- READ(uid_file, uid_buffer);
- i := OFS(uid_buffer.user_i_ptr^);
- IF i <> sys_version THEN
- BEGIN;
- WRITELN('Wanted version ', sys_version, ' user file');
- WRITELN('Got version ', i, ' user file');
- HALT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Read in the user file *)
- (*-----------------------------------------------------------------------*)
-
- uid_chain := NIL;
- uid_free := NIL;
-
- uid_total := 0;
-
- i := FILESIZE(uid_file) - 1;
-
- WHILE uid_total < i DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Read in the next record *)
- (*-------------------------------------------------------------------*)
-
- READ(uid_file, uid_buffer);
-
- (*-------------------------------------------------------------------*)
- (* Fill in fields as needed *)
- (*-------------------------------------------------------------------*)
-
- IF uid_buffer.user_n_time = 0 THEN
- uid_buffer.user_n_time := uid_buffer.user_last;
-
- IF uid_buffer.user_lang = #0 THEN
- uid_buffer.user_lang := '?';
-
- (*-------------------------------------------------------------------*)
- (* Build index *)
- (*-------------------------------------------------------------------*)
-
- NEW(uid_index_current);
-
- WITH uid_index_current^ DO
- BEGIN
-
- user_id := uid_buffer.user_id;
- user_recno := uid_total + 1;
-
- IF ((uid_buffer.user_flag AND user_f_delete) <> 0)
- OR (user_id = '') THEN
- BEGIN;
- user_next := uid_free;
- uid_free := uid_index_current;
- END
- ELSE
- insert_uid(uid_index_current);
-
- END;
-
- (*-------------------------------------------------------------------*)
- (* Bump record number *)
- (*-------------------------------------------------------------------*)
-
- uid_total := uid_total + 1;
-
- END; (*----- End of loop reading records ------------------------------*)
-
- END;
-
- (*===========================================================================*)
- (* Close uid file *)
- (*===========================================================================*)
-
- PROCEDURE close_uid;
-
- BEGIN;
- CLOSE(uid_file);
-
- END;